package site.brood.common.user.feign;


import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import site.brood.common.core.user.LoginUserVO;
import site.brood.common.core.web.AjaxJson;
import site.brood.common.user.pojo.UserDto;

/**
 * 用户服务降级处理
 */
@Slf4j
@Component
public class UserFallbackFactory implements FallbackFactory<UserFeign> {
    @Override
    public UserFeign create(Throwable throwable) {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new UserFeign(){
            @Override
            public AjaxJson<LoginUserVO> getByName(String userName, String source) {
                return AjaxJson.errorByMessage("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public AjaxJson<Boolean> add(UserDto userDto, String source) {
                return AjaxJson.errorByMessage("新增用户失败:" + throwable.getMessage());
            }
        };
    }
}
